home *** CD-ROM | disk | FTP | other *** search
- # ListCopy - deep copy of the lists
- # BsplineShowEval - returns list of polylines showing steps of the algorithm
- # at particular point
- # BsplineFindInterval - returns J such that t in [T_j, T_j+1)
- # BsplineShowIntervals - returns list of curve pieces connection points
- # BsplineShowWithPolygon - returns list of objects: curve, control polygon,
- # control points and BsplineShowIntervals
- # BsplineShowAll - returns complete list of objects demonstrating algorithm
- # steps at specific parameter value t and views it
- # BsplineAnimateEval - animates BsplineShowAll at parameter value samples
- #
- # Michael Plavnik
- #
- #iritState("EchoSource", false);
-
- order = 4;
-
- ListCopy = FUNCTION( argList) : len : i :
- len = sizeof( argList ) :
- return = NIL() :
- FOR (i = 1, 1, len, snoc( nth( argList, i ), return ) );
-
- BsplineShowEval = FUNCTION(k, polyList, knotList, J, t)
- # returns list of polylines demonstrating steps of the algorithm at parameter t
- : pList : pl : t_kpi : t_i : t_0 : t_1 : i : ii : p : colorValue :
- polyCurve : PtNew : td : Index :
- pList = NIL() :
- return = NIL() :
- colorValue = 3 :
- FOR(ii = J-k+1, 1, J, snoc( nth( polyList, ii+1 ), pList ) ) :
- FOR(p = 1, 1, k-1,
- pl = NIL() :
- FOR(i = J-k+1+p, 1, J,
- t_kpi = nth(knotList, i+k-p+1) :
- t_i = nth(knotList, i+1) :
- td = t_kpi - t_i :
- t_0 = (t - t_i) / ( t_kpi - t_i ) :
- t_1 = 1 - t_0 :
- Index = i-J+k-p :
- PtNew = coerce(
- t_0 * coerce(nth(pList, Index + 1 ), VECTOR_TYPE) +
- t_1 * coerce(nth(pList, Index ), VECTOR_TYPE),
- E2) :
- snoc( PtNew, pl )
- ) :
- color( pl, colorValue ) :
- snoc(pl, return) :
- IF (sizeof(pl) > 1,
- polyCurve = cbspline(2, pl, list(KV_OPEN)) :
- color( polyCurve, colorValue ) :
- colorValue = colorValue + 1 :
- snoc( polyCurve, return )
- ) :
- pList = ListCopy( pl )
- );
-
- BsplineFindInterval = FUNCTION(order, knotList, t)
- # returns J such that t in [T_j, T_j+1), where T_j stands for knotList[j]
- : i : len :
- return = 0 :
- len = sizeof(knotList) - order - 1 :
- FOR (i = order-1, 1, len,
- IF (t >= nth(knotList, i+1),
- return = i) );
-
- BsplineShowIntervals = FUNCTION(order, polyList, knotList, splineCurve)
- # return list of connection points between pieces
- : piece_list : i :
- piece_list = NIL() :
- FOR(i = 1, 1, sizeof(polyList)-1,
- snoc( ceval(splineCurve, nth(knotList, i+order-1)), piece_list )
- ) :
- color(piece_list, 10) :
- return = piece_list ;
-
- BsplineShowWithPolygon = FUNCTION(k, polyList, knotList)
- # returns list of curve, its polygon and polygon points visualy
- : spline_curve : polygon_curve :
- spline_curve = cbspline(k, polyList, knotList ) :
- polygon_curve = cbspline(2, polyList, list( KV_OPEN ) ) :
- color( spline_curve, YELLOW ) :
- color( polygon_curve, MAGENTA ) :
- color( polyList, MAGENTA ) :
- return = list( spline_curve, polygon_curve, polyList ) +
- BsplineShowIntervals(k, polyList, knotList, spline_curve);
-
- BsplineShowAll = FUNCTION(k, polyList, knotList, t)
- : J :
- J = BsplineFindInterval(k, knotList, t) :
- return = list(
- BsplineShowWithPolygon(order, polyList, knotList),
- BsplineShowEval(order, polyList, knotList, J, t)
- ) :
- view( return, TRUE );
-
- BsplineAnimateEval = PROCEDURE(resolution, k, polyList, knotList)
- : i : step : t : J :
- FOR (J = order-1, 1, sizeof(polyList)-1,
- t = nth(knotList, J+1) :
- step = (nth(knotList, J+2) - t) / resolution :
- FOR (i = 1, 1, resolution,
- view( list( BsplineShowWithPolygon(order, polyList, knotList),
- BsplineShowEval(order, polyList, knotList, J, t)
- ),
- TRUE
- ) :
- printf("J = %g t = %f\\n", list( J, t) ) :
- t = t + step
- )
- );
-
- iritState("EchoSource", true);
-
- #
- # Set the view state
- #
- view_mat = sc( 0.4 );
- viewobj( list( view_mat ) );
- viewstate( "WiderLns" );
-
- #
- # example 8.1
- #
- order = 4;
- knot_list = list( 0, 0, 0, 0, 1, 4, 5, 5, 5, 5 );
- polygon_list = list( ctlpt( E2, -1, -2),
- ctlpt( E2, -2, -1),
- ctlpt( E2, -1, 1),
- ctlpt( E2, 1, 1),
- ctlpt( E2, 2, -1),
- ctlpt( E2, 2, 0) );
-
- BsplineShowAll(order, polygon_list, knot_list, 2);
- pause();
-
- BsplineAnimateEval( 40, order, polygon_list, knot_list );
- BsplineAnimateEval( 40, order, polygon_list, knot_list );
- pause();
-
- #
- # example 8.2
- #
- order = 3;
- knot_list = list( 0, 0, 0, 1, 3, 4, 4, 4 );
- polygon_list = list( ctlpt( E2, -1, -2),
- ctlpt( E2, -2, -1),
- ctlpt( E2, -1, 1),
- ctlpt( E2, 1, 1),
- ctlpt( E2, 2, 0) );
-
-
- BsplineShowAll( order, polygon_list, knot_list, 0.7);
- pause();
-
- BsplineShowAll( order, polygon_list, knot_list, 1.7);
- pause();
-
- BsplineAnimateEval( 40, order, polygon_list, knot_list );
- BsplineAnimateEval( 40, order, polygon_list, knot_list );
- pause();
-
- #
- # Bezier case
- #
- order = 5;
- knot_list = list( 0, 0, 0, 0, 0, 1, 1, 1, 1, 1 );
- polygon_list = list( ctlpt( E2, -1, -2),
- ctlpt( E2, -2, -1),
- ctlpt( E2, -1, 1),
- ctlpt( E2, 1, 1),
- ctlpt( E2, 2, 0) );
-
- BsplineShowAll( order, polygon_list, knot_list, 0.35 );
- pause();
-
- BsplineAnimateEval( 70, order, polygon_list, knot_list );
- BsplineAnimateEval( 70, order, polygon_list, knot_list );
- pause();
-